#include <iostream>
#include <fstream>
#define min(x,y) (x)>(y)?(y):(x)


signed main() {
    long long n, maxn = 0x3f3f3f3f3fll;
    std::fstream cin("C:\\Users\\lenovo\\Desktop\\3.in", std::ios::in), 
    cout("C:\\Users\\lenovo\\Desktop\\3.out", std::ios::out);
    cin >> n;
    for (int i = 1; i <= n * 2; ++ i) {
        for (int j = 1; j <= n; ++ j) {
            long long num;
            cin >> num;
            if (num <= 2022) maxn = min(maxn, 2022 - num);
            else maxn = min(maxn, 4294969318ll - num);
        }
    }
    long long ans = 0;
    for (int i = 0; ; ++ i) {
        ans += i;
        if (ans >= maxn) {
            cout << i;
            break;
        }
    }
    return 0;
}